﻿/*******************************************************************************
 * Copyright @ 2017 YunSpace.Framework 版权所有
 * Author: GaoTang
 * Description: YunSpace 快速开发平台
 * Website：http://www.yunspace.com.cn
*********************************************************************************/
#region USING SYSTEM
using YunSpace.Core;
using YunSpace.Domain.Entity.WorkFlow;
using YunSpace.Domain.IRepository.WorkFlow;
using YunSpace.Repository.WorkFlow;
using System.Collections.Generic;
using System.Linq;
#endregion

namespace YunSpace.Application.WorkFlow
{
    public class ButtonsApp
    {
        private IButtonsRepository service = new ButtonsRepository();

        public List<ButtonsEntity> GetList(string keyword = "")
        {
            var expression = ExtLinq.True<ButtonsEntity>();
            if (!string.IsNullOrEmpty(keyword))
            {
                expression = expression.And(t => t.F_Title.Contains(keyword));
            }
            return service.IQueryable(expression).OrderBy(t => t.F_Sort).ToList();
        }
        //public List<ButtonsEntity> GetList(Pagination pagination, string queryJson)
        //{
        //    var expression = ExtLinq.True<ButtonsEntity>();
        //    var queryParam = queryJson.ToJObject();
        //    if (!queryParam["keyword"].IsEmpty())
        //    {
        //        string keyword = queryParam["keyword"].ToString();
        //        expression = expression.And(t => t.F_Account.Contains(keyword));
        //    }
        //    if (!queryParam["timeType"].IsEmpty())
        //    {
        //        string timeType = queryParam["timeType"].ToString();
        //        DateTime startTime = DateTime.Now.ToString("yyyy-MM-dd").ToDate();
        //        DateTime endTime = DateTime.Now.ToString("yyyy-MM-dd").ToDate().AddDays(1);
        //        switch (timeType)
        //        {
        //            case "1":
        //                break;
        //            case "2":
        //                startTime = DateTime.Now.AddDays(-7);
        //                break;
        //            case "3":
        //                startTime = DateTime.Now.AddMonths(-1);
        //                break;
        //            case "4":
        //                startTime = DateTime.Now.AddMonths(-3);
        //                break;
        //            default:
        //                break;
        //        }
        //        expression = expression.And(t => t.F_Date >= startTime && t.F_Date <= endTime);
        //    }
        //    return service.FindList(expression, pagination);
        //}

        public ButtonsEntity GetForm(string keyValue)
        {
            return service.FindEntity(keyValue);
        }
        public void DeleteForm(string keyValue)
        {
            service.Delete(t => t.F_Id == keyValue);
        }
        public void SubmitForm(ButtonsEntity buttonsEntity, string keyValue)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                buttonsEntity.Modify(keyValue);
                service.Update(buttonsEntity);
            }
            else
            {
                buttonsEntity.Create();
                buttonsEntity.F_Sort = service.GetMaxSort() + 1;
                service.Insert(buttonsEntity);
            }
        }
    }
}

